package com.lonely.fx.mouse;

import javafx.application.Application;
import javafx.beans.binding.DoubleBinding;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseDragEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
 * @date: 2022-07-27 13:34
 * @author: ztkj-hzb
 * @description: 鼠标事件 属性设置
 **/
public class MouseDrawEventSettingMain extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    /**
     *
     */
    @Override
    public void start(Stage primaryStage) throws Exception {

        VBox vBox = new VBox();
        vBox.setSpacing(50);
        vBox.setStyle("-fx-background-color: pink");

        Button button = new Button("Button");

        HBox hbox = new HBox();
        hbox.setPrefHeight(200);


        //设置拖拽检测---主要是用于开启拖拽监听流程，否则 setOnMouseDragOver,setOnMouseDragEntered 等事件都无法触发
        // 只会触发一次
        button.setOnDragDetected(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                //开启拖拽全流程
                button.startFullDrag();
                //System.out.println("触发 dragDetected 事件");
            }
        });

        //设置鼠标拖拽事件---这个事件是一个全功能的事件，可以拖拽出范围外
        button.setOnMouseDragged(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                //System.out.println("触发 mouseDragged 事件");
            }
        });

        //设置鼠标移动在组件内触发-----在组件内拖拽会一直触发
        button.setOnMouseDragOver(new EventHandler<MouseDragEvent>() {
            @Override
            public void handle(MouseDragEvent event) {
                System.out.println("触发 mouseDragOver 事件");
            }
        });

        //设置鼠标拖拽到组件内触发
        hbox.setOnMouseDragEntered(new EventHandler<MouseDragEvent>() {
            @Override
            public void handle(MouseDragEvent event) {
                System.out.println("触发 mouseDragEntered 事件");
            }
        });

        //设置鼠标拖拽出组件触发
        hbox.setOnMouseDragExited(new EventHandler<MouseDragEvent>() {
            @Override
            public void handle(MouseDragEvent event) {
                System.out.println("触发 mouseDragExited 事件");
            }
        });

        //松开拖拽触发
        hbox.setOnMouseDragReleased(new EventHandler<MouseDragEvent>() {
            @Override
            public void handle(MouseDragEvent event) {
                System.out.println("触发 mouseDragReleased 事件");
            }
        });



        hbox.setStyle("-fx-background-color: #BBFFFF");
        vBox.getChildren().addAll(button,hbox);
        primaryStage.setScene(new Scene(vBox));
        primaryStage.setWidth(600);
        primaryStage.setHeight(500);
        primaryStage.show();

    }
}
